package cn.wolfcode.controller;

import cn.wolfcode.domain.Travel;
import cn.wolfcode.query.TravelQuery;
import cn.wolfcode.service.ITravelService;
import cn.wolfcode.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("travel")
public class TravelController {

    @Autowired
    private ITravelService travelService;

    @RequestMapping("list")
    public Object list(Model model,TravelQuery qo){
        Page query = travelService.query(qo);
        model.addAttribute("qo",qo);
        model.addAttribute("page",query);
        return "/travel/list";
    }

    @RequestMapping("changeAudit")
    @ResponseBody
    public Object changeAudit(String id,int state){
        travelService.changeAudit(id,state);
        return JsonResult.success();
    }

    @RequestMapping("getContentById")
    @ResponseBody
    public Object getContentById(String id){
        Travel travel = travelService.get(id);
        return JsonResult.success(travel.getContent());
    }
}
